Release 10.1A: OpenEdge Development:
Programming Interfaces
Writing queries using the CONTAINS operator
Once you associate a compiled word-break table with a database that has word indexes, if necessary, populate the database and rebuild the word indexes. You can then write queries that use the
CONTAINSoperator.Syntax of the CONTAINS operator of the WHERE option
The
CONTAINSoperator has the following syntax in theWHEREoption of the record phrase:
fieldA field or array of type
CHARACTERthat participates in a word index.string-expressionAn expression of type
CHARACTERthat represents possible contents offield.The syntax of
string–expressionis as follows:
wordThe word to search for.
The ampersand (&) represents logical
AND, while the vertical bar (|), the exclamation point (!), and the caret (^) represent logicalOR.ANDlimits your search to records that contain all words you specify, whileORenlarges your search to include any word you specify. You can combineANDs andORs withinstring–expression. You can also group items with parentheses to create complex search conditions.You can use a wild card on the end of a string. For example, the string “sales*” represents “sales,” “saleswoman,” “salesman,” “salesperson,” and similar strings.
You can also define a character variable and assign a value to that variable.
Examples of the CONTAINS operator
Now that you know the syntax of the
CONTAINSoperator, you can write queries that use it.The following query, which displays all Item records whose Cat–description field contains the word “hockey,” demonstrates the
CONTAINSoperator in its simplest form:
The following is the equivalent query in SQL-89, which also allows
CONTAINS:
A
CONTAINSstring can contain multiple words connected by theANDoperator (ANDor &) and theORoperator (OR, |, or ^), optionally grouped by parentheses. For example:
Note: The
ANDoperator takes precedence over theORoperator. To override this default, use parentheses. Using parentheses can also make the text of a query clearer.A
CONTAINSstring containing multiple contiguous words, such as:
is equivalent to a
CONTAINSstring containing multiple words connected byAND, such as:
If a
CONTAINSstring contains multiple words, the order of the words is not significant. To retrieve records in a specific order, use theCONTAINSoperator with theMATCHESoperator. The followingWHEREclause retrieves records whose comments field contains the words “credit” and “hold” in that order, perhaps with other words in between:
Word indexes are case insensitive unless a field participating in the word index is case sensitive. The following two
WHEREclauses are equivalent:
You can combine
CONTAINSwith other search criteria, as in the followingWHEREclause, which searches for records whose city field is Boston and whose comments field contains the word “credit” and either the word “hold” or “watch”:
The following example demonstrates the use of a variable with the
CONTAINSoperator within theWHEREclause:
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |